# Maintainer: Orhun Parmaksız <orhun@archlinux.org>
# Contributor: Yigit Sever <yigit at yigitsever dot com>

pkgname=ouch
pkgver=0.4.2
pkgrel=1
pkgdesc="A command line utility for easily compressing and decompressing files and directories"
arch=('loong64' 'x86_64')
url="https://github.com/ouch-org/ouch"
license=('MIT')
depends=('xz' 'bzip2' 'zlib')
makedepends=('cargo')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/refs/tags/${pkgver}.tar.gz")
sha256sums=('08015fa92770515cfa00570bc5f0f0a4f28f0ad238f360f3579ac043723a6ec2')
options=('!lto')

prepare() {
  cd "$srcdir/$pkgname-$pkgver"
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "$srcdir/$pkgname-$pkgver"
  OUCH_ARTIFACTS_FOLDER=artifacts cargo build --frozen --release --all-features
}

check() {
  cd "$srcdir/$pkgname-$pkgver"
  cargo test --frozen --all-features
}

package() {
  cd "$srcdir/$pkgname-$pkgver"

  install -Dm0755 -t "$pkgdir/usr/bin/" "target/release/$pkgname"
  install -Dm0644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm0644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"

  cd "$srcdir/$pkgname-$pkgver/artifacts"

  # install manpages
  install -Dm0644 "${pkgname}.1" -t "${pkgdir}/usr/share/man/man1"
  install -Dm0644 "${pkgname}-compress.1" -t "${pkgdir}/usr/share/man/man1"
  install -Dm0644 "${pkgname}-decompress.1" -t "${pkgdir}/usr/share/man/man1"
  install -Dm0644 "${pkgname}-list.1" -t "${pkgdir}/usr/share/man/man1"

  # install shell completions
  install -Dm0644 "${pkgname}.bash" "${pkgdir}/usr/share/bash-completion/completions/${pkgname}"
  install -Dm0644 "${pkgname}.fish" "${pkgdir}/usr/share/fish/vendor_completions.d/${pkgname}.fish"
  install -Dm0644 "_${pkgname}" "${pkgdir}/usr/share/zsh/site-functions/_${pkgname}"
}

# vim: ts=2 sw=2 et:
